//
//  KKGoodsEditView.m
//  Butler
//
//  Created by liaozhenming on 16/6/22.
//  Copyright © 2016年 liaozhenming. All rights reserved.
//

#import "KKGoodsEditView.h"

@interface KKGoodsEditView()<UITextFieldDelegate>

@property (nonatomic, strong) UICollectionView *categoryCollectionView;

@end

@implementation KKGoodsEditView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame: frame];
    if (self) {
        
        UIView *contentView = [self contentView];
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, CGRectGetWidth(contentView.bounds), 44)];
        titleLabel.backgroundColor = [UIColor kk_colorWithHexString: @"71d47c"];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.text = @"新增商品";
        [contentView addSubview: titleLabel];
        
        UIImageView *headerImageView = [[UIImageView alloc] initWithFrame: CGRectMake(20, 64, 120, 120)];
        headerImageView.backgroundColor = [UIColor yellowColor];
        [contentView addSubview: headerImageView];
        
        CGFloat pointY = 80;
        {
            UILabel *nameTipsLabel = [[UILabel alloc] initWithFrame: CGRectMake(150, pointY, 100, 20)];
            nameTipsLabel.backgroundColor = [UIColor clearColor];
            nameTipsLabel.text = @"商品名称:";
            nameTipsLabel.textColor = [UIColor kk_colorWithHexString: @"555555"];
            [contentView addSubview: nameTipsLabel];
            
            UITextField *textField = [[UITextField alloc] initWithFrame: CGRectMake(180, pointY + 25, CGRectGetWidth(contentView.bounds) - 200, 26)];
            textField.borderStyle = UITextBorderStyleRoundedRect;
            textField.delegate = self;
            [contentView addSubview: textField];
            pointY += 60;
        }
        
        {
            UILabel *nameTipsLabel = [[UILabel alloc] initWithFrame: CGRectMake(150, pointY, 100, 20)];
            nameTipsLabel.backgroundColor = [UIColor clearColor];
            nameTipsLabel.text = @"商品价格:";
            nameTipsLabel.textColor = [UIColor kk_colorWithHexString: @"555555"];
            [contentView addSubview: nameTipsLabel];
            
            UITextField *textField = [[UITextField alloc] initWithFrame: CGRectMake(180, pointY + 25, CGRectGetWidth(contentView.bounds) - 200, 26)];
            textField.borderStyle = UITextBorderStyleRoundedRect;
            textField.delegate = self;
            [contentView addSubview: textField];
            pointY += 60;
        }
        
        {
            UILabel *nameTipsLabel = [[UILabel alloc] initWithFrame: CGRectMake(150, pointY, 100, 20)];
            nameTipsLabel.backgroundColor = [UIColor clearColor];
            nameTipsLabel.text = @"商品分类:";
            nameTipsLabel.textColor = [UIColor kk_colorWithHexString: @"555555"];
            [contentView addSubview: nameTipsLabel];
            
            UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
            _categoryCollectionView = [[UICollectionView alloc] initWithFrame: CGRectMake(250, pointY, CGRectGetWidth(contentView.bounds) - 260, 40) collectionViewLayout: flowLayout];
            [contentView addSubview: _categoryCollectionView];
        }

        UIButton *cancelButton = [UIButton buttonWithType: UIButtonTypeSystem];
        cancelButton.frame = CGRectMake(30, CGRectGetHeight(contentView.bounds) - 50, 120, 34);
        cancelButton.backgroundColor = [UIColor kk_colorWithHexString: @"71d47c"];
        [cancelButton setTitle: @"取消" forState: UIControlStateNormal];
        [cancelButton setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal];
        [cancelButton addTarget: self action: @selector(action_cancel:) forControlEvents: UIControlEventTouchUpInside];
        [cancelButton kk_cornerRadius: 3.0];
        [contentView addSubview: cancelButton];
        
        UIButton *sureButton = [UIButton buttonWithType: UIButtonTypeSystem];
        sureButton.frame = CGRectMake(CGRectGetWidth(contentView.bounds) - 150, CGRectGetHeight(contentView.bounds) - 50, 120, 34);
        sureButton.backgroundColor = [UIColor kk_colorWithHexString: @"71d47c"];
        [sureButton setTitle: @"确定" forState: UIControlStateNormal];
        [sureButton setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal];
        [sureButton addTarget: self action: @selector(action_save:) forControlEvents: UIControlEventTouchUpInside];
        [sureButton kk_cornerRadius: 3.0];
        [contentView addSubview: sureButton];
    }
    return self;
}

#pragma mark - Action methods

- (void)action_cancel:(UIBarButtonItem*)item {
    
    [self kk_close];
}

- (void)action_save:(UIBarButtonItem*)item {
    
    [self kk_close];
}

@end
